<%@page import="com.situ.personal.entity.Role"%>
<%@page import="java.util.List"%>
<%@page import="com.situ.personal.entity.PageInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>

	<%
	PageInfo pageInfo = (PageInfo)request.getAttribute("RolePageInfo"); 
	// out.println(pageInfo);
	List<Role> list = pageInfo.getList();
	%>
	
	<a class="btn btn-primary" href="<%=request.getContextPath()%>/role_insert.jsp">添加</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<th>编号ID</th>
			<th>角色名称</th>
			<th>sn编码</th>
			<th>功能_删除</th>
			<th>功能_修改</th>
		</tr>
		<%
			for (Role role : list) {
		%>
				<tr>
					<td><%=role.getId()%></td>
					<td><%=role.getName()%></td>
					<td><%=role.getSn()%></td>
					<td><a href="javascript:void(0)" onclick="deleteById(<%=role.getId()%>)">删除</a></td>
					<td><a href="<%=request.getContextPath()%>/role?method=selectById&id=<%=role.getId()%>">修改</a></td>
					<!-- request.getContextPath() 返回当前项目名字 -->
				</tr>
		<%
			}
		%>
	</table>
	
	<!-- 这里是显示   页码     的地方 -->
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	  
	  <!-- 《1，2,，3》  -->
	  <!-- 上一页箭头， 页码， 下一页箭头  -->
	  
	  
	  <!-- 上一页按钮 开始 -->
	  <%
	  	if(pageInfo.getPageNo() == 1){
	  %>	
	        <!-- 放到上面  显示禁止按钮 -->
	  	<li class="disabled" ><a href="#"  aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
	  <%	
	  	}else{
 	  %>
 	     <li><a href="<%=request.getContextPath()%>/role?method=findByPage&pageNo=<%=pageInfo.getPageNo()-1%>" aria-label="Previous">
 	      				<span aria-hidden="true">&laquo;</span></a></li>
 	 <% 		
	  	}
	  %>
	   <!-- 上一页按钮 结束 -->
	   
	   
	  <!-- 页码 按钮  开始-->
	    <%
	    	int totalPage = pageInfo.getTotalPage(); // 页码个数     有几个   就遍历几个a
	    	for (int i = 1; i <= totalPage; i++) {
	    		
	    		//  做一个判断    如果(getPageNo当前页) == (i 遍历每一页的当前页 )    
	    		//		就高亮   ( 如果已经在当前页就 a="#"，不然原来写法，又会执行执行一遍  [拿着method i 去servlet/ teacher里面 浪费性能  ]) ，，，   
	    		//       否则  就原来 写法   ( 跳转那页 获取i页码值   拿着method i 去servlet/ teacher里面 )
	   			if(pageInfo.getPageNo() == i){
	   	%>
	   						<!-- 高亮 -->
	   				<li class="active"><a href="#"> <%=i%> </a></li>
	   	<%
	   			}else{
		%>																			<!-- 页码是个变量  1 2 3…… -->
					<li><a href="<%=request.getContextPath()%>/role?method=findByPage&pageNo=<%=i%>"> <%=i%> </a></li>
								<!--点击那个a,,,就   找/teacherServlet  ?方法找findByPage & 当前页码是%=i%  -->
		<%
	   			}
	    	}
	    %>
	      <!-- 页码 按钮  结束-->
	      
	      
	
	    	  <!--下一页按钮 开始 -->
	  <%
	  	if(pageInfo.getPageNo() == pageInfo.getTotalPage()){
	  %>	
	        <!-- 放到上面  显示禁止按钮 -->
	  	<li class="disabled" ><a href="#"  aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
	  <%	
	  	}else{
 	  %>
 	     <li><a href="<%=request.getContextPath()%>/role?method=findByPage&pageNo=<%=pageInfo.getPageNo()+1%>" aria-label="Previous">
 	      				<span aria-hidden="true">&laquo;</span></a></li>
 	 <% 		
	  	}
	  %>
	   <!-- 下一页按钮 结束 -->  
	      
	      


	  </ul>
	</nav>
	
<!-- 	<script type="text/javascript">
		function deleteById(id) {
			var isDel = confirm("您确认要删除么？");
			if (isDel) {
				// location.href = "/SiTu/deleteStudent?id=" + id;
				 location.href = "/SiTuMVC/student?method=deleteById&id=" + id;
			}
		}
	</script> -->
	<script type="text/javascript">
		function deleteById(id){
			var isDel = confirm("您确定删除吗？");
			if (isDel) {
				location.href="/SiTuPersonal/role?method=deleteById&id="+id;
			}
		}
	</script>
	
</body>
</html>